""" Calculate descriptive statistics for Table 3"""

import sys
import pandas as pd

class _Logger(object):

    def __init__(self, fname=''):

        # Redirect STDOUT
        self.terminal = sys.stdout

        # Write APPEND to Log
        self.log = open(fname, mode="a")

    def write(self, msg):
        self.terminal.write(msg)
        self.log.write(msg)
        self.log.flush()

    def flush(self):
        pass

sys.stdout = _Logger(fname='results/02_descriptive_stats.txt')

print('\n\n')
print('=' * 80)
print('Calculate Descriptive Statistics')
print('=' * 80)


df = pd.read_csv('data/descriptive_stats.csv')

df1 = df[df.config==1]
df3 = df[df.config==3]
df10 = df[df.config==10]
df12 = df[df.config==12]

print('Config 1', '\n\n')
print('MEAN')
print(df1.mean())
print('~' * 40)
print('STD')
print(df1.std())

print('\n\n')
print('-' * 80)
print('\n\n')

print('Config 3', '\n\n')
print('MEAN')
print(df3.mean())
print('~' * 40)
print('STD')
print(df3.std())

print('\n\n')
print('-' * 80)
print('\n\n')

print('Config 10', '\n\n')
print('MEAN')
print(df10.mean())
print('~' * 40)
print('STD')
print(df10.std())

print('\n\n')
print('-' * 80)
print('\n\n')

print('Config 12', '\n\n')
print('MEAN')
print(df12.mean())
print('~' * 40)
print('STD')
print(df12.std())